import Workplace from "../components/layout/workplace";
import { useSession } from "next-auth/react";
import { User } from "../components/user";
import { Breadcrumb, Row } from "antd";
import useSWR from "swr";
import fetcher from "../components/fetcher";
import LoadingSpin from "../components/spin-loading";

type HomeProps = {
  user: User;
};

const Home = (props: HomeProps) => {
  const { data: session, status } = useSession();
  console.log(session);
  const { data, error } = useSWR("/api/profile", fetcher);
  // BUG: data may not always be ready, so when read data.name, it will fail
  if (error) {
    console.log("fetch data error:", error);
  }
  if (!data) {
    return <LoadingSpin />;
  }

  return (
    <Workplace currentTab="home" profile={data}>
      <Row>
        <h1>Home</h1>
      </Row>
    </Workplace>
  );
};

Home.auth = true;
export default Home;
